package top.chengdongqing.mishop.common.quartz

import org.quartz.*
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import top.chengdongqing.mishop.order.job.OrderCancellationJob

@Configuration
class QuartzConfigurer {

    @Bean
    fun orderCancellationJobDetail(): JobDetail {
        return JobBuilder.newJob(OrderCancellationJob::class.java)
            .storeDurably()
            .build()
    }

    @Bean
    fun orderCancellationJobTrigger(): Trigger {
        val schedule = SimpleScheduleBuilder.simpleSchedule()
            .withIntervalInMinutes(5)
            .repeatForever()
        val startAt = DateBuilder.futureDate(5, DateBuilder.IntervalUnit.MINUTE)

        return TriggerBuilder.newTrigger()
            .forJob(orderCancellationJobDetail())
            .withSchedule(schedule)
            .startAt(startAt)
            .build()
    }
}